home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
tclocks.arc
/
CLOCKWRK.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1990-12-17
|
6KB
|
260 lines
program TestPlatform;
uses Objects, Drivers, Views, Menus, App,
Dos, { for the paramcount and paramstr funcs}
Clocks; { for the clock on the menubar object, TClockMenu }
{ This generic test platform has been hooked up to the clock-on-the-menubar
object / unit. Search for *** to find hook-up points.
Copyright (c) 1990 by Danny Thorpe
}
const cmNewWin = 100;
cmFileOpen = 101;
WinCount : Integer = 0;
MaxLines = 50;
type PInterior = ^TInterior;
TInterior = object(TScroller)
constructor init(var Bounds: TRect; AHScrollbar, AVScrollbar: PScrollbar);
procedure Draw; virtual;
end;
PDemoWindow = ^TDemoWindow;
TDemoWindow = object(TWindow)
constructor Init(WindowNo: integer);
end;
TMyApp = object(TApplication)
procedure InitStatusLine; virtual;
procedure InitMenuBar; virtual;
procedure NewWindow;
procedure HandleEvent( var Event: TEvent); virtual;
procedure Idle; virtual;
end;
var MyApp: TMyApp;
Lines: array [0..MaxLines-1] of PString;
LineCount: Integer;
constructor TInterior.Init(var Bounds: TRect; AHScrollbar, AVScrollbar: PScrollbar);
begin
TScroller.Init(Bounds,AHScrollbar,AVScrollbar);
Growmode := gfGrowHiX + gfGrowHiY;
Options := Options or ofFramed;
SetLimit(128,LineCount);
end;
procedure TInterior.Draw;
var color: byte;
y,i: integer;
B: TDrawBuffer;
begin
TScroller.Draw;
Color := GetColor($01);
for y:= 0 to Size.Y -1 do
begin
MoveChar(B,' ',Color,Size.X);
I := Delta.Y + Y;
if (I<Linecount) and (Lines[I] <> nil) then
MoveStr(B,Copy(Lines[I]^,Delta.X+1,size.x),Color);
WriteLine(0,y,size.x,1,B);
end;
end;
procedure ReadFile;
var F: text;
S: string;
begin
LineCount:=0;
if paramcount = 0 then
assign(F,'clockwrk.pas')
else
assign(F,paramstr(1));
reset(F);
while not eof(F) and (linecount < maxlines) do
begin
readln(f,s);
Lines[Linecount] := NewStr(S);
Inc(LineCount);
end;
Close(F);
end;
constructor TDemoWindow.Init(WindowNo: Integer);
var LInterior, RInterior: PInterior;
HScrollbar, VScrollbar: PScrollbar;
R: TRect;
Center: integer;
begin
R.Assign(0,0,40,15);
R.Move(Random(40),Random(8));
TWindow.Init(R, 'Window', wnNoNumber);
GetExtent(R);
Center:= (R.B.X + R.A.X) div 2;
R.Assign(Center,R.A.Y+1,Center+1,R.B.Y-1);
VScrollbar:= new(PScrollbar, Init(R));
with VScrollbar^ do Options := Options or ofPostProcess;
Insert(VScrollbar);
GetExtent(R);
R.Assign(R.A.X+2,R.B.Y-1,Center-1,R.B.Y);
HScrollbar:= new(PScrollbar, Init(R));
with HScrollbar^ do Options := Options or ofPostProcess;
Insert(HScrollbar);
GetExtent(R);
R.Assign(R.A.X+1,R.A.Y+1,Center,R.B.Y-1);
LInterior:= new(PInterior, Init(R, HScrollbar, VScrollbar));
with LInterior^ do
begin
Options:= Options or ofFramed;
Growmode:= GrowMode or gfGrowHiX;
SetLimit(128,LineCount);
end;
Insert(LInterior);
GetExtent(R);
R.Assign(R.B.X-1,R.A.Y+1,R.B.X,R.B.Y-1);
VScrollbar:= new(PScrollbar, Init(R));
with VScrollbar^ do Options := Options or ofPostProcess;
Insert(VScrollbar);
GetExtent(R);
R.Assign(Center+2,R.B.Y-1,R.B.X-2,R.B.Y);
HScrollbar:= new(PScrollbar, Init(R));
with HScrollbar^ do
begin
Options := Options or ofPostProcess;
GrowMode:= GrowMode or gfGrowLoX;
end;
Insert(HScrollbar);
GetExtent(R);
R.Assign(Center+1,R.A.Y+1,R.B.X-1,R.B.Y-1);
RInterior:= new(PInterior, Init(R, HScrollbar, VScrollbar));
with RInterior^ do
begin
Options:= Options or ofFramed;
Growmode:= GrowMode or gfGrowLoX;
SetLimit(128,LineCount);
end;
Insert(RInterior);
end;
procedure TMyApp.InitStatusLine;
var R: TRect;
begin
GetExtent(R); { find out how big the current view is }
R.A.Y := R.B.Y-1; { squeeze R down to one line at bottom of frame }
StatusLine := New(PStatusline, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
NewStatusKey('~F4~ New', kbF4, cmNewWin,
NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
nil))),
nil)
));
end;
{ *** The vvv below indicate the primary hook-up point for the menubar-clock.
This programmer-defined normal menu structure will be tacked onto the
end of the clock menubar in TClockMenu.Init.
}
procedure TMyApp.InitMenuBar;
var R: TRect;
begin
GetExtent(R); {***}
r.b.y:= r.a.y+1; { vvv }
Menubar := New(PClockMenu, Init(R, NewMenu(
NewSubMenu('~F~ile', hcNoContext, NewMenu(
NewItem('~O~pen','F3', kbF3, cmFileOpen, hcNoContext,
NewItem('~N~ew','F4', kbF4, cmNewWin, hcNoContext,
NewLine(
NewItem('E~x~it','Alt-X', kbAltX, cmQuit, hcNoContext,
nil))))),
NewSubMenu('~W~indow', hcNoContext, NewMenu(
NewItem('~N~ext','F6', kbF6, cmNext, hcNoContext,
NewItem('~Z~oom','F7', kbF7, cmZoom, hcNoContext,
nil))),
nil)) { one ) for each menu defined }
)));
end;
procedure TMyApp.NewWindow;
var
Window: PDemoWindow;
R: TRect;
begin
inc(WinCount);
Window:= New(PDemoWindow, Init(WinCount));
Desktop^.Insert(Window);
end;
{*** clock hook-up point - typecasting required to access "new" method }
procedure TMyApp.Idle;
begin
TApplication.Idle;
PClockMenu(MenuBar)^.Update;
end;
procedure TMyApp.HandleEvent( var Event: TEvent);
begin
TApplication.HandleEvent(Event);
if Event.What = evCommand then
begin
case Event.Command of
cmNewWin: NewWindow;
else { case }
Exit;
end; { case }
ClearEvent(Event);
end; {if}
end;
begin
readfile;
MyApp.Init;
MyApp.run;
MyApp.done;
end.